﻿using Microsoft.Xna.Framework;
using SomeGame.GUI.WidgetActions;
using SomeGame.GUI.Widgets.Containers;

namespace SomeGame.GUI.Screens {

    public abstract class Screen {

        private readonly WidgetActionProcessor WidgetActionProcessor = new WidgetActionProcessor();
        public bool IsTopScreen;
        public string Name;
        protected RootContainer RootContainer;

        public virtual void Update(GameTime gameTime) {
            WidgetActionProcessor.Update(gameTime);
            if (WidgetActionProcessor.IsActive) {
                RootContainer.Layout();
            }
            RootContainer.Update(gameTime); // Any screen with game objects needs this.
        }

        public void Draw() {
            DrawGameObjects();
            DrawWidets();
        }

        protected virtual void DrawGameObjects() {
            // Doing nothing is the default.
        }

        private void DrawWidets() {
            // Screen position to world position. Container 'catches up' to camera, puts itself at zero in camera's current view.
            Vector2 zeroInWorldCoords = Vector2.Transform(RootContainer.Origin, Matrix.Invert(GameEngine.CameraTransformation));
            RootContainer.Bounds = new Rectangle((int)zeroInWorldCoords.X, 
                                                 (int)zeroInWorldCoords.Y, 
                                                 RootContainer.Bounds.Width, 
                                                 RootContainer.Bounds.Height);
            RootContainer.Draw();
        }

    }

}